<?php

use Illuminate\Support\Facades\DB;

function successMsg($data)
{
    return \GuzzleHttp\json_encode(['code' => 0,'msg' => 'SUCCESS','data' => $data],JSON_UNESCAPED_UNICODE);

}
function errorMsg()
{
    return \GuzzleHttp\json_encode(['code' => -1,'msg' => 'ERROR','data' => null],JSON_UNESCAPED_UNICODE);
}
function objToArr($obj){
    return \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($obj));
}
//后台菜单
function getMenuByPid($pid)
{
    $data = DB::table('menu')->where("pid",$pid)->get();
    $res  = [];
    //遍历 递归
    foreach ($data as $key => $value) {
        // 代码段：核心点
        $value->menu = getMenuByPid($value->id);
        $res[]         = $value;
    }
    return $res;
}